package src.Fourteen;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class mouse extends JFrame {

    public mouse(){
        final JLabel label = new JLabel();
        label.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("鼠标按键被按下，");
                int button = e.getButton();
                if(button == MouseEvent.BUTTON1){
                    System.out.println("按下鼠标左键");
                }
                if(button == MouseEvent.BUTTON2){
                    System.out.println("按下鼠标滚轮");
                }
                if(button == MouseEvent.BUTTON3){
                    System.out.println("按下鼠标右键");
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
                System.out.println("鼠标按键被按下，");
                int button = e.getButton();
                System.out.println("mousePressed:"+button);
                if(button == MouseEvent.BUTTON1){
                    System.out.println("按下鼠标左键");
                }
                if(button == MouseEvent.BUTTON2){
                    System.out.println("按下鼠标滚轮");
                }
                if(button == MouseEvent.BUTTON3){
                    System.out.println("按下鼠标右键");
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                System.out.println("鼠标按键被释放，");
                int button = e.getButton();
                System.out.println("mouseReleased:"+button);
                if(button == MouseEvent.BUTTON1){
                    System.out.println("释放鼠标左键");
                }
                if(button == MouseEvent.BUTTON2){
                    System.out.println("释放鼠标滚轮");
                }
                if(button == MouseEvent.BUTTON3){
                    System.out.println("释放鼠标右键");
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                System.out.println("光标移入组件");
            }

            @Override
            public void mouseExited(MouseEvent e) {
                System.out.println("光标移出组件");
            }
        });

        Container container = getContentPane();
        container.add(label);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(500,500);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        mouse m = new mouse();
    }
}
